﻿#include "form4.h"
#include "ui_form4.h"

#include "cairo.h"
#include <QDebug>
#include <QPainter>

Form4::Form4(QWidget *parent)
    : QWidget(parent),
      ui(new Ui::Form4)
{
    ui->setupUi(this);
}

Form4::~Form4()
{
    delete ui;
}

void Form4::paintEvent(QPaintEvent *pEvent) //原生的绘图
{
    Q_UNUSED(pEvent);

    //创建一张图QImage
    QImage image;
    image.load("d:\\clr.jpg"); //clr

    //贴图
    QPainter painter(this);
    painter.drawImage(this->rect(), image);

    //画线
    painter.setRenderHint(QPainter::Antialiasing, true); //抗锯齿
    QPen pen(Qt::magenta, 1.0);
    painter.setPen(pen);
    painter.drawLine(QPoint(0, 0), QPoint(100, 100));
    painter.drawLine(QPoint(100, 100), QPoint(100, 200));

    //写文本
    painter.setFont(QFont("Sans", 90, QFont::Bold));
    painter.drawText(QPointF(10, 150), "Hello");
}
